package com.itruth.util;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ThreadPool {
	
	private static ThreadPool instance;
	
	private ExecutorService cachePool;
	
	private ThreadPool() {
		cachePool = Executors.newCachedThreadPool();
	}
	
	public static ThreadPool getIns() {
		
		if (null == instance) {
			synchronized (ThreadPool.class) {
				if (null == instance) {
					instance = new ThreadPool();
				}
			}
		}
		
		return instance;
	}
	
	public void addTaskToCachePool(Runnable task) {
		
		if (null != cachePool) {
			cachePool.execute(task);
		}
		
	}
	
	public void closeCachePool() {
		cachePool.shutdownNow();
		cachePool = null;
		  
	}
}
